Keep HTTPError as a base class for .request() and .raise_for_status()#1125
Keep HTTPError as a base class for .request() and .raise_for_status()#1125lovelydinosaur merged 1 commit intomasterfrom
Conversation
|
This looks great, with one question, is there a reason you're explicitly not using |
Absolutely, yup. The remaining cases are due to programmatic errors. It's not typically useful to catch and handle those cases, and including them in Of the remaining cases...
|
|
Ah, well, that explains why I've never really needed those other exceptions! I think that's a reasonable explanation and I'd recommend that something similar (or even just what you wrote) definitely be included in the documentation. |
florimondmanca
left a comment
There was a problem hiding this comment.
Sounds about right to me! I'm also feeling we could keep this w/o deprecation, it's probably a nice handy feature (which I agree should be documented but I understand we haven't started documenting the exception hierarchy just yet).
|
The |
Closes #1108, and following rationale in #1083 (comment), which I'll repeat here...
I think there's probably also a decent case to make for not deprecating it at all, and instead keeping it as a base class, but only for
RequestErrorandHTTPStatusError, so that...Which means existing code all keeps working as expected, while still providing finer-grained classes where needed.
It's also more concise than the alternative...
This hadn't really occurred to me when looking at #1095.
The typing is also still nice and clear here. Both
HTTPStatusErrorandRequestErrorprovide.request, so we can suitably annotate that on the base class. However accessing.responseonhttpx.HTTPErrorwould be a typing error, since it could either be aRequestError(which isn't associated with a response) or aHTTPStatusError(which is).The following are all valid...
I think this is probably all a usability win for our users given...
except httpx.HTTPError as exc:is more concise thanexcept (httpx.RequestError, httpx.StatusCodeError) as exc:How do we feel about this?